import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/dialog/filter_dialog/custom_filter_right_sheet.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/emergency/exercise_plan_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/drill/common/drill_common_widget.dart';
import 'package:enterprise_v6_app/app/modules/application/emergency/drill/drill_plan/drill_plan_controller.dart';

/// 演练计划列表
class DrillPlanPage extends StatelessWidget {
  DrillPlanPage({super.key});

  final controller = Get.put(DrillPlanController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            key: controller.popRightScaffoldKey,
            endDrawer: Container(
              width: AppDimens.sw - 80.w,
              height: AppDimens.sh,
              color: Colors.white,
              child: _getFilterWidget(),
            ),
            body: Container(
              color: const Color(0xffF5F5F6),
              padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
              child: Column(children: [
                _getSearchConditionWidget(),
                AppGaps.vGap12,
                Expanded(
                    child: CustomEasyRefreshList<ExercisePlanEntity>(
                  key: controller.globalKey,
                  dataLoad: (pageIndex, pageSize, {String? search}) async {
                    return controller.getListData(pageIndex, pageSize);
                  },
                  itemBuilder: (ExercisePlanEntity item, int index) {
                    return CustomTitleChartPage(
                      title: item.exercisePlanName,
                      titleRightWidget: DrillPlanCommonWidget().getStateView(item.toExamineStatus),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          CustomTextWidget.getTextRowView(title: '演练类别：', value: item.exercisePlanClassName),
                          AppGaps.vGap12,
                          CustomTextWidget.getTextRowView(title: '演练类型：', value: item.exercisePlanTypeName),
                          AppGaps.vGap12,
                          CustomTextWidget.getTextRowView(title: '预案名称：', value: item.emergencyIdName),
                        ],
                      ),
                    ).clickOnce(() {
                      controller.jumpToDetails(id: item.id);
                    });
                  },
                ))
              ]),
            ),
          );
        });
  }

  ///获取右侧筛选样式
  Widget _getFilterWidget() {
    return CustomFilterRightSheet(
      dataList: controller.allFilterList,
      onConfirm: controller.screenConfirm,
      topSpacing: AppGaps.vGap20,
      isRadio: true,
    );
  }


  ///获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Row(
      children: [
        Expanded(
            child: CustomSearchEnter(
          height: 32.w,
          hintText: '请输入名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        )),
        AppGaps.hGap8,
        _screen(),
      ],
    );
  }

  ///筛选
  Widget _screen() {
    return Container(
      width: 36.w,
      height: 32.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 18.w,
        height: 16.w,
      ),
    ).clickOnce(controller.screen);
  }
}
